package com.mmlc.meimei.lichengkongjian.home;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mmlc.inter.InterAdapter;
import com.mmlc.meimei.lichengkongjian.R;
import com.mmlc.network.responsebean.NewProductListResponseBean;
import com.mmlc.utils.ViewUtils;
import com.mmlc.utils.XUtils;

import java.util.List;

/**
 * Created by Administrator on 2016/7/14.
 */
public class RecommendAdapter extends InterAdapter<NewProductListResponseBean.DataBean.GoodslistBean> {

    public RecommendAdapter(Context context, List<NewProductListResponseBean.DataBean.GoodslistBean> datas) {
        super(context, datas);
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view == null) {
            holder = new ViewHolder();
            view = LayoutInflater.from(context).inflate(R.layout.item_recommend, viewGroup, false);
            holder.iv_avatar = ViewUtils.getView(view, R.id.iv_avatar);
            holder.tv_brand = ViewUtils.getView(view,R.id.tv_brand);
            holder.tv_name = ViewUtils.getView(view, R.id.tv_name);
            holder.tv_price = ViewUtils.getView(view, R.id.tv_price);
            holder.tv_market_price = ViewUtils.getView(view, R.id.tv_market_price);
            holder.layout_discount = ViewUtils.getView(view,R.id.layout_discount);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        NewProductListResponseBean.DataBean.GoodslistBean product = datas.get(i);
        if (holder.iv_avatar != null && !ViewUtils.isEmpty(product.getImg_thumb())) {
            XUtils.image(holder.iv_avatar, product.getImg_thumb());
        }
        if (holder.tv_brand != null && !ViewUtils.isEmpty(product.getBrand_name())) {
            holder.tv_brand.setText(product.getBrand_name());
        }
        if (holder.tv_name != null && !ViewUtils.isEmpty(product.getGoods_name())) {
            holder.tv_name.setText(product.getGoods_name());
        }
//        holder.tv_market_price.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
//        holder.tv_market_price.setText("¥"+product.getMarket_price());

        if (holder.tv_market_price != null && !ViewUtils.isEmpty(product.getDiscount())) {
            holder.tv_market_price.setText(product.getDiscount());
        }else if(holder.tv_market_price != null && ViewUtils.isEmpty(product.getDiscount())){
            holder.tv_market_price.setVisibility(View.GONE);
        }
        if (holder.tv_price != null && !ViewUtils.isEmpty(product.getPrice())) {
            holder.tv_price.setText("¥ " + product.getPrice());
        }
        if(holder.layout_discount != null && !ViewUtils.isEmpty(product.getDiscount())){
            holder.layout_discount.setVisibility(View.VISIBLE);
        }else {
            holder.layout_discount.setVisibility(View.GONE);
        }

        return view;
    }

    class ViewHolder {
        ImageView iv_avatar;
        TextView tv_brand,tv_name, tv_price, tv_market_price;
        LinearLayout layout_discount;
    }
}
